package cn.itrip.order.service;

import cn.itrip.dao.ItripUserLinkUserMapper;
import cn.itrip.pojo.ItripUserLinkUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ItripUserLinkUserServiceImpl implements ItripUserLinkUserService{

    @Resource
    private ItripUserLinkUserMapper itripUserLinkUserMapper;

    /**
     * 根据旅客信息查询旅客列表
     * @param itripUserLinkUser
     * @return
     */
    @Override
    public List<ItripUserLinkUser> queryByLinkList(ItripUserLinkUser itripUserLinkUser) {
        return itripUserLinkUserMapper.selectByLinkUser(itripUserLinkUser);
    }

    /**
     * 保存旅客信息
     * @param itripUserLinkUser
     * @return
     */
    @Override
    public Boolean saveUserLink(ItripUserLinkUser itripUserLinkUser) throws Exception {
        if(itripUserLinkUser.getUserid()!=null)
        {
            itripUserLinkUser.setCreatedby(Long.parseLong(itripUserLinkUser.getUserid().toString()));
        }
        itripUserLinkUser.setCreationdate(new Date());
        return itripUserLinkUserMapper.insertSelective(itripUserLinkUser)>0;

    }

    /**
     * 修改旅客信息
     * @param itripUserLinkUser
     * @return
     */
    @Override
    public Boolean modifierUserLink(ItripUserLinkUser itripUserLinkUser) throws Exception {

        if(itripUserLinkUser.getLinkusername() == null || itripUserLinkUser.getLinkidcard() == null || itripUserLinkUser.getUserid() == null){

            throw new Exception("参数为空！");

        }
        itripUserLinkUser.setModifydate(new Date());
        itripUserLinkUser.setModifiedby(Long.parseLong(itripUserLinkUser.getUserid().toString()));
        return itripUserLinkUserMapper.updateByPrimaryKeySelective(itripUserLinkUser)>0;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public Boolean deleteUserLink(Long id) {
        return itripUserLinkUserMapper.deleteByPrimaryKey(id)>0;
    }


}
